knitr::opts_chunk$set(echo = TRUE)
Obtain the working directory.
getwd()
Read in the DDT data.
ddt <- read.csv("DDT.csv") head(ddt)
a. The qualitative variables are RIVER and SPECIES. b. The quantitative variables are MILE, LENGTH, WEIGHT, and DDT. c. The ddt data has 3 species. d. Show only entries with species LMBASS and weight >800g.
with(ddt,ddt[SPECIES=="LMBASS" & WEIGHT>800,])
e. Show only entries with river SCM and DDT >4.0.
with(ddt,ddt[RIVER=="SCM" & DDT>4.0,])
Q1. Find the mean of the lengths.
mean(ddt$LENGTH)
Q2. Find the standard deviation of the weights.
sd(ddt$WEIGHT)
Q3. Does the image match the plot of length vs weight? Answer: No
plot(LENGTH~WEIGHT,data=ddt)
Q4. If v=1:20, the last value of v/20 is 1.
v=1:20 v/20
Make tables and barplots.
riv = with(ddt,table(RIVER)) riv barplot(riv,col=1:4) rivsp = with(ddt,table(RIVER,SPECIES)) rivsp barplot(rivsp)
Make pie charts.
sp = with(ddt,table(SPECIES)) pie(sp) pie(riv)
Make boxplots.
boxplot(DDT~SPECIES,data=ddt) boxplot(WEIGHT~SPECIES,data=ddt) boxplot(LENGTH~RIVER,data=ddt)
Make coplots.
coplot(LENGTH~WEIGHT|RIVER,data=ddt) coplot(DDT~WEIGHT|SPECIES,data=ddt)
Use ggplot to make different types of plots.
library(ggplot2)
ggplot(data=ddt,aes(x=SPECIES,y=WEIGHT,fill=RIVER))+geom_boxplot()+ggtitle("Drake Taylor") ggplot(data=ddt,aes(x=RIVER,y=LENGTH,fill=SPECIES))+geom_violin()+ggtitle("Drake Taylor") ggplot(data=ddt,aes(x=WEIGHT,y=LENGTH,color=SPECIES))+geom_point()+ggtitle("Drake Taylor")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.